<template>
  <div>
    <h2 style="text-align: center">采购邀请</h2>
    <el-row>
      <el-col :span="5">
        标题：
        <el-input size="large" style="width: 200px;" v-model="queryObj.title" placeholder="请输入采购邀请标题"/>
      </el-col>
      <el-col :span="6">
        起始日期：
        <el-date-picker
            v-model="queryObj.startDate"
            type="date"
            placeholder="请选择开始日期"
            size="large"
            value-format="YYYY-MM-DD"
        />
      </el-col>
      <el-col :span="6">
        结束日期：
        <el-date-picker
            v-model="queryObj.endDate"
            type="date"
            placeholder="请选择结束日期"
            size="large"
            value-format="YYYY-MM-DD"
        />
      </el-col>
      <el-col :span="6">
        状态：
        <el-select v-model="queryObj.status" class="m-2" placeholder="选择状态" clearable size="large">
          <el-option
              v-for="item in [{lable:'进行中',value:0},{lable:'已完成',value:1}]"
              :key="item.value"
              :label="item.lable"
              :value="item.value"
          />
        </el-select>
      </el-col>

      <el-col :span="1">
        <el-button type="primary" @click="findInvite(1)">搜索</el-button>
      </el-col>
    </el-row>

    <el-table :data="inviteList" stripe height="400" style="width: 100%">
      <el-table-column label="采购邀请编号" prop="invite.inviteId"/>
      <el-table-column label="标题" prop="invite.title"/>
      <el-table-column label="时间" prop="invite.dateTime"/>
      <el-table-column label="状态">
        <template #default="scope">
          <el-text v-if="scope.row.invite.status===0" class="mx-1" type="success">进行中</el-text>
          <el-text v-if="scope.row.invite.status===1" class="mx-1" type="info">已完成</el-text>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-badge :hidden="scope.row.readStatus===1" value="未读" class="item">
            <el-button size="default" type="primary" @click="findById(scope.row.id),showFindById=true">
              查看详情
            </el-button>
          </el-badge>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog v-model="showFindById" :title="inviteObj.title" width="70%" :before-close="handleClose" center>
      时间:{{ inviteObj.dateTime }}<br><br>
      <div v-html="inviteObj.info" style="height:300px;border: black 1px solid"></div>

      <template #footer>
      <span class="dialog-footer">
        <el-button type="primary"
                   @click="$router.push({path:'/bidd',query: {id:inviteObj.inviteId}})">添加标书</el-button>
      </span>
      </template>
    </el-dialog>

    <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        background
        layout="prev, pager, next, jumper"
        :total="total"
        @current-change="findInvite"
    />
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      inviteList: [],
      total: 0,
      currentPage: 1,
      pageSize: 6,
      queryObj: {},
      inviteObj: {},
      showFindById: false,
    }
  },
  methods: {
    findInvite(pageNO) {
      this.currentPage = pageNO;
      this.queryObj.pageNO = pageNO
      axios.get("/project/invite/cutByItem", {params: this.queryObj})
          .then(resp => {
            let obj = resp.data;
            if (obj.success) {
              this.inviteList = obj.data.records;
              this.total = obj.data.total;
              this.pageSize = obj.data.size
            }
          })
    },
    findById(id) {
      axios.get("/project/invite/findById", {params: {id}})
          .then(resp => {
            let obj = resp.data;
            if (obj.success) {
              this.inviteObj = obj.data
              // console.log(obj.data)
              this.findInvite(1)
            }
          })
    }
  }, created() {
    this.findInvite(1)
  }
}
</script>

<style scoped>
.item {
  margin-top: 10px;
  margin-right: 40px;
}
</style>